package com.example.modulepicselector.internal.entity;

import android.content.ContentUris;
import android.database.Cursor;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import android.provider.MediaStore;

public class Item implements Parcelable {

    public final Uri uri;
    public final long size;
    public final long id;
    public  Uri hdUri;



    protected Item(Parcel in) {
        uri = in.readParcelable(Uri.class.getClassLoader());
        size = in.readLong();
        id = in.readLong();
    }

    public static final Creator<Item> CREATOR = new Creator<Item>() {
        @Override
        public Item createFromParcel(Parcel in) {
            return new Item(in);
        }

        @Override
        public Item[] newArray(int size) {
            return new Item[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeParcelable(uri, flags);
        dest.writeLong(size);
        dest.writeLong(id);
    }

    private Item(long id, long size) {
        this.id = id;
        Uri contentUri;
            contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;

        this.uri = ContentUris.withAppendedId(contentUri, id);
        this.size = size;
    }


    public Uri getUri() {
        return uri;
    }

    public long getSize() {
        return size;
    }

    public long getId() {
        return id;
    }

    public static Item valueOf(Cursor cursor) {
        return new Item(cursor.getLong(cursor.getColumnIndex(MediaStore.Files.FileColumns._ID)),
                cursor.getLong(cursor.getColumnIndex(MediaStore.MediaColumns.SIZE)));
    }

    public Uri getHdUri() {
        return hdUri;
    }

    public void setHdUri(Uri hdUri) {
        this.hdUri = hdUri;
    }
}
